<template>
  <div>
    <div class="search_form">
			<div>
				<el-date-picker
					size="mini"
					v-model="searchForm.workDate"
					type="date"
					format="yyyy年MM月dd日"
					value-format="yyyy-MM-dd"
					placeholder="选择日期"
					class="others"
          clearable
				></el-date-picker>
				<el-button @click="searchData" class="search_btn" type="primary" icon="el-icon-search" size="mini">
					查询
				</el-button>
			</div>
      <div>
        <el-button size="mini" type="primary" @click="handlerClickdb">导入</el-button>
      </div>
		</div>
    <BaseTableCheck 
      :loading="loading"
      ref="trustOrderData"
      :data="tableData"
      :columns="columns" 
      @checkId="workTaskSelChange"
      :tableHT="tableHeight" 
      :pagination="queryall" 
      @size-change="sizeChange" 
      @current-change="pageChange" ></BaseTableCheck>
  </div>
</template>
<script>
import BaseTableCheck from '@/components/BaseTable/baseTablecheck'
import BaseTable from '@/components/BaseTable'
import publicapi from '@/api/public/index'
import api from '@/api/Dispatch/operationPlan/index'
export default {
  components: { BaseTable,BaseTableCheck },
  props: {
    closeDrawer: {
      type: Function
    },
    setformData: {
      type: Function
    }
  },
  data() {
    return{
      searchForm: {
        workDate: '',
      },
      loading: false,
      tableData: [],
      columns: [
        {
          prop: 'trustNo',
          label: '指令编号',
        },
        {
          prop: 'customerName',
          label: '客户名称',
          isShort: true,
        },
        {
          prop: 'processName',
          label: '作业过程',
        },
        {
          prop: 'planQuantity',
          label: '计划件数',
        },
        {
          prop: 'planTon',
          label: '计划重量',
        },
        {
          prop: 'planVolume',
          label: '计划体积',
        },
        {
          prop: 'planCarNum',
          label: '计划车数',
        },
        {
          prop: 'remark',
          label: '作业要求',
        },
        {
          prop: 'shipvoyageName',
          label: '船名航次',
        },
        {
          prop: 'companyName',
          label: '组织',
        },
      ],
      tableHeight: window.innerHeight - 200,
      // 页码
      queryall: {
        totalNum: 0,
        startpage: 1,
        pagesize: 15
      },
      formLabelAlign: {
        time: '',
        workTime: '',
      },
      workTimeList: [],
      workDataList: [], //选中的作业指令
    }
  },
  created() {
    //  日期默认当天
		let date = new Date()
		let theYear = date.getFullYear() //获取完整的年份(4位)
		let theMonth = date.getMonth() + 1 //获取当前月份(1-12,1代表1月)
		theMonth = theMonth >= 10 ? theMonth : "0" + theMonth
		let theDay = date.getDate() //获取当前日(1-31)
		theDay = theDay >= 10 ? theDay : "0" + theDay
    this.searchForm.workDate = theYear+'-'+theMonth+'-'+theDay
    this.formLabelAlign.time = theYear+'-'+theMonth+'-'+theDay
  },
  mounted() {
    this.getDictData()
    this.searchData()
  },
  methods: {
    // 查询字典信息
    getDictData () {
      publicapi.getDictData('SCHEDULE').then(res => {
        this.workTimeList = res.data.data.SCHEDULE
      })
    },
    // 查询列表信息
    searchData () {
      let params = Object.assign({},this.queryall,this.searchForm)
      params.status = '3'
      // params.isPlan = 'Y'
      params.isGathering = 'Y'
      api.getTrustOrderData(params).then(res => {
        this.tableData = res.data.data.pages
        this.queryall.startpage = res.data.data.pageNum // 当前页
        this.queryall.pagesize = res.data.data.pageSize // 每页多少
        this.queryall.totalNum = res.data.data.totalNum
      })
    },
    // 重置搜索信息
    resetFormForBusiness () {
      this.searchForm = {
        workDate: '',
      }
    },
    // 分页查询
    sizeChange(val) {
      this.queryall.pagesize = val;
      this.searchData();
    },
    // 分页查询
    pageChange(val) {
      this.queryall.startpage = val;
      this.searchData();
    },
    // 选中的复选框
    workTaskSelChange (val) {
      console.log(val)
      this.workDataList = val;
    },
    // 导入
    sureimport () {
      if (!this.formLabelAlign.workTime) {
        return this.$message.warning('请选择班次')
      }
      console.log(this.workDataList)
      if (this.workDataList.length == 0) {
        this.$message.warning("请最少勾选一条数据")
				return
      }
      this.workDataList.forEach(v => {
        v.workDate = this.formLabelAlign.time
        v.workTime = this.formLabelAlign.workTime
        v.trustId = v.id
        v.planNo = v.trustNo + '-1'
        v.planType = '1'
        v.id = ''
      })
      api.importTrust(this.workDataList).then(res => {
        if (res.data.code != '0000') {
          return this.$message.error(res.data.msg)
        }
        this.closeDrawer()
        this.$message.success('新增成功')
      })
    },
    // 勾选导入
    handlerClickdb (val) {
      if (this.workDataList.length == 0) {
        this.$message.warning("请勾选一条数据")
				return
      }
      if (this.workDataList.length > 1) {
        this.$message.warning("请勾选一条数据")
				return
      }
      this.setformData(this.workDataList[0])
    },
  }
}
</script>
<style lang="less" scoped>
@import "../../../../assets/searchfrom.less";
@import "./index.less";
</style>